package com.example.riceexambackend.dao.mapper;

import com.example.riceexambackend.dao.dataobject.QuestionDO;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface QuestionMapper {

    /**
     * 插入题目记录
     * @param questionDO
     */
    @Insert("insert into t_question (question_name, option_a, option_b, option_c, option_d, right_answer, upload_user_id, question_type_id) values (#{questionName}, #{optionA}, #{optionB}, #{optionC}, #{optionD}, #{rightAnswer}, #{uploadUserId}, #{questionTypeId})")
    @Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id")
    void insertQuestion(QuestionDO questionDO);

    /**
     * 根据id查询题目
     * @param questionId
     */
    @Select("select * from t_question where id = #{questionId} and delete_flag = 0")
    QuestionDO selectById(@Param("questionId") Long questionId);

    /**
     * 根据名称查询题目
     * @param questionName
     */
    @Select("select * from t_question where question_name = #{questionName}")
    QuestionDO selectByName(@Param("questionName") String questionName);

    /**
     * 查询所有题目
     */
    @Select("select * from t_question where delete_flag = 0")
    List<QuestionDO> selectList();
}
